FROM python:3.7-slim-buster as base

# Builder
FROM base as builder

ARG OPENCVE_VERSION

RUN apt-get update && apt-get upgrade -y && apt-get install -y \
    git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /opencve

RUN git clone https://github.com/opencve/opencve.git . && git checkout tags/v${OPENCVE_VERSION} -b ${OPENCVE_VERSION}

WORKDIR /app

RUN python3 -m venv /app/venv

ENV PATH="/app/venv/bin:$PATH"

RUN python3 -m pip install --upgrade pip

RUN python3 -m pip install /opencve/

COPY run.sh .

# OpenCVE Image
FROM base

LABEL name="opencve"
LABEL maintainer="dev@opencve.io"
LABEL url="https://github.com/opencve/opencve"

RUN apt-get update && apt-get upgrade -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/ /app/

WORKDIR /app

ENV PATH="/app/venv/bin:$PATH"

ENV OPENCVE_HOME="/app"

ENTRYPOINT ["./run.sh"]
